Ext.define('SKJF.view.PEMBELIAN.v_purchasertn', {
	extend: 'Ext.grid.Panel',
	requires: ['SKJF.store.s_purchasertn'],
	
	title		: 'purchasertn',
	itemId		: 'Listpurchasertn',
	alias       : 'widget.Listpurchasertn',
	store 		: 's_purchasertn',
	columnLines : true,
	frame		: false,
	
	margin		: 0,
	selectedIndex : -1,
	
	initComponent: function(){
		var me = this;
		var docktool = Ext.create('Ext.toolbar.Paging', {
			store: 's_purchasertn',
			dock: 'bottom',
			displayInfo: true
		});		
		this.columns = [
			{
				header: 'NOMOR_PURCHASE_RETURN',filterable:true,
				dataIndex: 'NOMOR_PURCHASE_RETURN'
			},{
				header: 'TANGGAL_PURCHASE_RETURN',filterable:true,
				dataIndex: 'TANGGAL_PURCHASE_RETURN',
				renderer: Ext.util.Format.dateRenderer('d M, Y')
			},{
				header: 'NOMOR_LPB',filterable:true,
				dataIndex: 'NOMOR_LPB'
			},{
				header: 'APA_IMPORT',filterable:true,
				dataIndex: 'APA_IMPORT'
			},{
				header: 'KODE_SUPPLIER',filterable:true,
				dataIndex: 'KODE_SUPPLIER'
			},{
				header: 'NAMA_SUPPLIER',filterable:true,
				dataIndex: 'NAMA_SUPPLIER'
			},{
				header: 'ALAMAT_SUPPLIER',filterable:true,
				dataIndex: 'ALAMAT_SUPPLIER'
			},{
				header: 'TELPON_SUPPLIER',filterable:true,
				dataIndex: 'TELPON_SUPPLIER'
			},{
				header: 'FAX_SUPPLIER',filterable:true,
				dataIndex: 'FAX_SUPPLIER'
			},{
				header: 'CURRENCY',filterable:true,
				dataIndex: 'CURRENCY'
			},{
				header: 'KURS',filterable:true,
				dataIndex: 'KURS'
			},{
				header: 'SUB_TOTAL',filterable:true,
				dataIndex: 'SUB_TOTAL',
				align: 'right'
				// renderer: function(value){
					// return Ext.util.Format.currency(value, 'Rp ', 2);
				// }
			},{
				header: 'PPN',filterable:true,
				dataIndex: 'PPN',
				align: 'right'
				// renderer: function(value){
					// return Ext.util.Format.currency(value, 'Rp ', 2);
				// }
			},{
				header: 'TOTAL',filterable:true,
				dataIndex: 'TOTAL',
				align: 'right'
				// renderer: function(value){
					// return Ext.util.Format.currency(value, 'Rp ', 2);
				// }
			},{
				header: 'MATERAI',filterable:true,
				dataIndex: 'MATERAI',
				align: 'right'
				// renderer: function(value){
					// return Ext.util.Format.currency(value, 'Rp ', 2);
				// }
			},{
				header: 'DIBUAT_OLEH',filterable:true,
				dataIndex: 'DIBUAT_OLEH'
			},{
				header: 'JUMLAH_EDIT',filterable:true,
				dataIndex: 'JUMLAH_EDIT'
			},{
				header: 'TANGGAL_EDIT',filterable:true,
				dataIndex: 'TANGGAL_EDIT',
				renderer: Ext.util.Format.dateRenderer('d M, Y')
			},{
				header: 'INFO',filterable:true,
				dataIndex: 'INFO'
			},{
				header: 'ID',filterable:true,
				dataIndex: 'ID'
			}];
		this.features = [{
				ftype: 'filters',
				autoReload: true,
				encode: false,
				local: true
			}
		];
		this.dockedItems = [
			Ext.create('Ext.toolbar.Toolbar', {
				items: [{
					xtype: 'fieldcontainer',
					layout: 'hbox',
					defaultType: 'button',
					items: [{
						itemId	: 'btncreate',
						text	: 'Add',
						iconCls	: 'icon-add',
						action	: 'create'
					}, {
						xtype: 'splitter'
					}, {
						itemId	: 'btndelete',
						text	: 'Delete',
						iconCls	: 'icon-remove',
						action	: 'delete',
						disabled: true
					}]
				}, '-', {
					xtype: 'fieldcontainer',
					layout: 'hbox',
					defaultType: 'button',
					items: [{
						itemId	: 'btnprint',
						text	: 'Cetak',
						iconCls	: 'icon-print',
						action	: 'print'
					}]
				}]
			}),docktool
		];
		
		docktool.add([{
				text: 'Clear Filter Data',
				handler: function () {
					me.filters.clearFilters();
				}
			}
		]);
		
		this.callParent(arguments);
		
		this.on('itemclick', this.gridSelection);
		this.getView().on('refresh', this.refreshSelection, this);
	},	
	
	gridSelection: function(me, record, item, index, e, eOpts){
		//me.getSelectionModel().select(index);
		this.selectedIndex = index;
		this.getView().saveScrollState();
	},
	
	refreshSelection: function() {
        this.getSelectionModel().select(this.selectedIndex);   /*Ext.defer(this.setScrollTop, 30, this, [this.getView().scrollState.top]);*/
    }

});